package com.alliance.shuwei.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alliance.shuwei.entity.Role;
import com.alliance.shuwei.repository.RoleDao;

@Service
@Transactional
public class RoleService {
	
	@Autowired
	private RoleDao roleDao;

	public List<Role> getAllRoles() {
		List<Role> roles = new ArrayList<Role>();
		Iterator<Role> iterator = roleDao.findAll().iterator();
		while (iterator.hasNext()) {
			roles.add(iterator.next());
		}
		return roles;
	}
	
	public Role createRole(Role role){
		return roleDao.save(role);
	}
	public Role updateRole(Role role){
		return roleDao.save(role);
	}
	
	public Role getRoleById(int id) {
		return roleDao.findOne(id);
	}
}
